package iosr11.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

public class ServiceLocatorImpl implements ServiceLocator {

	private Map<Class, Service> service;
	private Logger log = Logger.getLogger("service-log");
	private static ServiceLocatorImpl locator;
	
	public ServiceLocatorImpl(){
		service = new HashMap<Class, Service>();
		locator = this;
	}
	
	public static ServiceLocator getInstance(){
		return locator;
	}
	
	@Override
	public Service getService(Class entity) {
		Service tmp = service.get(entity);
		if (tmp==null){
			System.out.println("bald - brak serwisu");
			log.warning("brak zarejestrowanego srewisu dla danej nazwy");
			return null;
		}
		else {
			System.out.println("zwracam serwis "+tmp.getClass());
			log.info("zwracanie serwisu: "+tmp.getClass());
			return tmp;
		}
	}

	public void setAttendenceService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setEventSeriesService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setEventService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setGroupService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setMarkService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setProjectGroupService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setProjectSubjectService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setStudentService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setTeacherService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
	public void setNoteService(Service service) {
		this.service.put(service.getServiceEntityClass(), service);
	}
}
